﻿using CodeGenerator.BaseUI;
using CodeGenerator.Common;
using CodeGenerator.Core;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CodeGenerator.UI
{
    public partial class FrmSetup : BaseFormEx
    {
        public FrmSetup()
        {
            InitializeComponent();
        }

        private void FrmSetup_Load(object sender, EventArgs e)
        {
            MainSetting info = Config.GetSetupInfo();

            txtNameSpace.Text = info.NameSpace;
            txtAreaName.Text = info.AreaName;
            txtOutputDir.Text = info.OutputDir;
            txtPrefix.Text = info.Prefix;

            txtEntityName.Text = info.EntityPackage;
            txtDao.Text = info.DaoPackage;
            txtMapping.Text = info.Mapping;
            txtIservice.Text = info.IServicePackage;
            txtService.Text = info.ServicePackage;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnChoosePath_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
            folderBrowserDialog.ShowDialog();
            txtOutputDir.Text = folderBrowserDialog.SelectedPath;
        }

        private void btnSava_Click(object sender, EventArgs e)
        {
            MainSetting info = Config.GetSetupInfo();

            info.NameSpace = txtNameSpace.Text.Trim();
            info.AreaName = txtAreaName.Text.Trim();
            info.OutputDir = txtOutputDir.Text.Trim();
            info.Prefix = txtPrefix.Text.Trim();

            info.EntityPackage = txtEntityName.Text.Trim();
            info.DaoPackage = txtDao.Text.Trim();
            info.Mapping = txtMapping.Text.Trim();
            info.IServicePackage = txtIservice.Text.Trim();
            info.ServicePackage = txtService.Text.Trim();


            if (Config.EditSetupInfo(info))
            {
                if (MessageUtil.ConfirmYesNo("设置成功，是否关闭？"))
                    this.Close();
            }
            else
            {
                MessageUtil.ShowError("设置失败！");
            }
        }
    }
}
